﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class tbNhacc
    {
        private string mancc;

        public string Mancc
        {
            get { return mancc; }
            set { mancc = value; }
        }
        private string tenncc;

        public string Tenncc
        {
            get { return tenncc; }
            set { tenncc = value; }
        }
        private string diachi;

        public string Diachi
        {
            get { return diachi; }
            set { diachi = value; }
        }
        private string email;

        public string Email
        {
            get { return email; }
            set { email = value; }
        }
        private string sdt;

        public string Sdt
        {
            get { return sdt; }
            set { sdt = value; }
        }

        DBAccess db = new DBAccess();

        public DataTable dalDSNhacc()
        {
            string query = "HienThiNCC";
            SqlParameter[] param=new SqlParameter[1];
            param[0] = new SqlParameter("@MaNCC", Mancc);
            return db.GetDataTable(query, CommandType.StoredProcedure, param);
        }

        public bool dalThemNhacc()
        {
            bool res = false;
            string query = "ThemNCC";
            SqlParameter[] param = new SqlParameter[4];
            param[0] = new SqlParameter("@TenNCC", Tenncc );
            param[1] = new SqlParameter("@DiaChi", Diachi);
            param[2] = new SqlParameter("@Email", Email);
            param[3] = new SqlParameter("@SDT", Sdt);
            res = db.DoExcecute(query, CommandType.StoredProcedure, param);
            return res;
        }

        public bool dalSuaNhacc()
        {
            bool res = false;
            string query = "SuaNCC";
            SqlParameter[] param = new SqlParameter[5];
            param[0] = new SqlParameter("@TenNCC", Tenncc);
            param[1] = new SqlParameter("@DiaChi", Diachi);
            param[2] = new SqlParameter("@Email", Email);
            param[3] = new SqlParameter("@SDT", Sdt);
            param[4] = new SqlParameter("@MaNCC", Mancc);
            res=db.DoExcecute(query, CommandType.StoredProcedure, param);
            return res;
        }

        public bool dalXoaNhacc()
        {
            bool res2 = false;
            string query2 = "select * from CTNH where MaNCC=@MaNCC";
            SqlParameter[] param2 = new SqlParameter[1];
            param2[0] = new SqlParameter("@MaNCC", Mancc);
            res2 = db.DoExecuteReader(query2, CommandType.Text, param2);

            bool res = false;
            string query = "XoaNCC";
            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("@MaNCC", Mancc);

            if (res2 == true)
                res = false;
            else
            {
                res = db.DoExcecute(query, CommandType.StoredProcedure, param);
                res = true;
            }
            return res;
        }

    }

}
